#/bin/sh!
### NODA setting
SCRIPT_PATH=/net/alice22/scratch/scripts/openstack/

## ENV
echo ENV
source $SCRIPT_PATH/conffiles/ENV

servers="nova neutron"
controller=alice01

service_nova="
openstack-nova-compute
"

service_neutron="
neutron-openvswitch-agent
"

service02="$service_nova $service_neutron"
service01="libvirtd messagebus openvswitch"
INSTANCE_TUNNELS_INTERFACE_IP_ADDRESS=`hostname -i`


## END of ENV
echo END of ENV


## Package install
echo Package install
packages="openstack-nova-compute mysql openstack-neutron-ml2 openstack-neutron-openvswitch sysfsutils"

yum -y  install $packages
## End Package install
echo End Package install

## Service setting 01
echo Service setting 01

for serv in $service01; do
        service $serv start;
	chkconfig -add $serv;
        chkconfig $serv on;
done
ovs-vsctl add-br br-in

## END Service setting 01
echo END Service setting 01


##Configure files openstack
echo Configure files openstack

tmpfile=`mktemp`;
for fname in `ls ${SCRIPT_PATH}/conffiles/node/ |grep Zaroch_etc`; do
	conffile=`echo $fname | sed s#_Zaroch_#/#g`;
	cat ${SCRIPT_PATH}/conffiles/node/$fname | while read line; do
		echo "export atr=\"$line\"" > $tmpfile;
		source $tmpfile
		rm -f $tmpfile
		openstack-config --set $conffile $atr
	done
done

## END Configure files openstack
echo END Configure files openstack

## Last seting
echo Last seting

cd  /etc/neutron/
ln -s /etc/neutron/plugins/ml2/ml2_conf.ini /etc/neutron/plugin.ini
cp /etc/init.d/neutron-openvswitch-agent /etc/init.d/neutron-openvswitch-agent.orig
sed -i 's,plugins/openvswitch/ovs_neutron_plugin.ini,plugin.ini,g' /etc/init.d/neutron-openvswitch-agent
#echo "include /etc/cinder/volumes/*" >> /etc/tgt/targets.conf


## End last setting
echo  End last setting



## Service start and check
echo Service start and check

for serv in $service02 ; do
        service $serv restart;
        chkconfig $serv on;
done

## END Service start and check
echo END Service start and check

